<?
if($_POST["submit"])
{
	$dir = "C:\xampp\htdocs\tt\images\uploaded\\"; //directory your images should be uploaded to
	//$dir = "/home/content/r/e/d/redpanda/html/www/tankthat/images/uploaded/";
	$datei = $_FILES['upload']['tmp_name'];
	$dateiname = $_FILES['upload']['name'];
	$dateitype = $_FILES['upload']['type'];
	switch($dateitype)
	{
		case "image/gif":
			$types = ".gif";
			break;

		case "image/pjpeg":
			$types = ".jpg";
			break;

		case "image/jpeg":
			$types = ".jpg";
			break;

		case "image/x-png":
			$types = ".png";
			break;

		default:
			$types = false;
	}
	if (!file_exists($dir.$dateiname) && $types != false)
	{
		copy($datei,$dir.$dateiname);
?>		<script language="JavaScript">window.opener.insertHTML("<img src='.$dir.$dateiname.'>", "comment");self.close();</script>
<?php 
		//DONT FORGET TO REPLACE "YOURFIELDID" with the id of your textfield! - "comment"
	}
	else
	{
		echo "There was an error!"; //Errormessage
	}
}
else
{
	echo '<form method="POST" enctype="multipart/form-data" action=""><p><input type="file" name="upload" size="20"></p><p><input type="submit" name="submit" value="Upload"></p></form>';
}
?>